class KthLargest
{
public:
    KthLargest(int k, vector<int> &nums)
    {
        this->k = k;
        for (int num : nums)
        {
            this->add(num);
        }
    }

    int add(int val)
    {
        if (q.size() < k)
        {
            q.push(val);
        }
        else if (val > q.top())
        {
            q.pop();
            q.push(val);
        }
        return q.top();
    }

    priority_queue<int, vector<int>, greater<int>> q;
    int k;
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */